package com.gitee.smalllog.admin.view;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gitee.smalllog.admin.dto.SmallLogQueryDTO;
import com.gitee.smalllog.stored.model.LogEntity;
import com.gitee.smalllog.stored.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class IndexController {

    @Autowired
    LogService logService;

    @GetMapping({"/index", "/"})
    public String index() {
        return "index";
    }

    @PostMapping({"/getData"})
    @ResponseBody
    public Object getData(@RequestBody(required = false) SmallLogQueryDTO dto){
        dto = new SmallLogQueryDTO();
        dto.setPage(1);
        dto.setPageSize(10);
        IPage page = new Page(dto.getPage(), dto.getPageSize());
        LogEntity entity = new LogEntity();
        QueryWrapper<LogEntity> wrapper = new QueryWrapper<>();
        wrapper.setEntity(entity);
        return logService.page(page,wrapper);
    }
}
